<?php //strip
/**
 * Helper plugin that implements paging
 * 
 * @author Ondrej Donek <ondrejd@gmail.com>
 * @package odEshopWpPlugin
 */
class odWpEshopPluginPager
{
    
    /** 
     * Total items count
     * @var integer $mTotalItemsCount
     */
    var $mTotalItemsCount;
    
    /**
     * Holds count of items per single page
     * @var integer $mPerPageItemsCount
     */
    var $mPerPageItemsCount;
    
    /**
     * Holds total count of pages
     * @var integer $mTotalPagesCount
     */
    var $mTotalPagesCount;
    
    /**
     * Holds index of current page (checked from $_GET['p'])
     * @var integer $mCurrentPage
     */
    var $mCurrentPage;
    
    /**
     * Limit items (for the current page) from
     * @var integer $mLimitItemsFrom
     */
    var $mLimitItemsFrom;
    
    /**
     * Limit items (for the current page) to
     * @var integer $mLimitItemsTo
     */
    var $mLimitItemsTo;
    
    var $mUrlBase = '';
    
    /**
     * Constructor.
     * 
     * @param integer $aTotalItemsCount
     * @param integer $mPerPageItemsCount
     * @param integer $mCurrentPage
     * @return void
     */
    function odWpEshopPluginPager($aTotalItemsCount, $aPerPageItemsCount, $aCurrentPage = null)
    {
        $this->mTotalItemsCount = $aTotalItemsCount;
        $this->mPerPageItemsCount = $aPerPageItemsCount;
        $this->mTotalPagesCount = ceil($this->mTotalItemsCount / $this->mPerPageItemsCount);
        
        if(!is_null($aCurrentPage)) {
            $this->mCurrentPage = (int) $aCurrentPage;
        } else {
            $this->mCurrentPage = (isset($_GET['pn'])) ? (int) $_GET['pn'] : 1;
        }
        
        $this->mLimitItemsTo = $this->mCurrentPage * $this->mPerPageItemsCount;
        $this->mLimitItemsFrom = $this->mLimitItemsTo - $this->mPerPageItemsCount;
    }
    
    function setUrlPrefix($aUrlBase) {
    	$this->mUrlBase = $aUrlBase;
    }
    
    function getPreviousPageUrl() {
    	return $this->mUrlBase . '&amp;pn=' . (($this->mCurrentPage == 1) ? 1 : ($this->mCurrentPage - 1)); 
    }
    
    function getNextPageUrl() {
    	return $this->mUrlBase . '&amp;pn=' . ($this->mCurrentPage + 1); 
    }
    
}
